/**
 * 颜色分配Hook
 */

import { useMemo } from 'react';
import { Course, ProcessedCourse } from '../types/course';
import { processCourses } from '../utils/scheduleUtils';

export interface UseColorAllocationReturn {
  /** 处理后的课程列表（包含颜色信息） */
  processedCourses: ProcessedCourse[];
  /** 颜色映射表 */
  colorMap: Map<string, string>;
}

/**
 * 颜色分配Hook
 * @param courses 课程列表
 * @returns 处理后的课程数据和颜色映射
 */
export const useColorAllocation = (courses: Course[]): UseColorAllocationReturn => {
  const { processedCourses, colorMap } = useMemo(() => {
    const processed = processCourses(courses);
    const colorMapping = new Map<string, string>();
    
    processed.forEach(course => {
      const key = `${course.day_of_week}-${course.section.start}`;
      colorMapping.set(key, course.color);
    });
    
    return {
      processedCourses: processed,
      colorMap: colorMapping
    };
  }, [courses]);
  
  return { processedCourses, colorMap };
};
